package com.xjoyt.pay.master.dao.predicate;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang.StringUtils;

import com.xjoyt.pay.annotations.PredicateCommand;
import com.xjoyt.pay.master.params.CashDetailPageParam;
import com.xjoyt.pay.master.po.CashDetail;

public class CashDetailCommands {
	@PredicateCommand
	public List<Predicate> queryCommand(CashDetailPageParam param, Root<CashDetail> root, CriteriaQuery<?> query,
			CriteriaBuilder cb) {

		if (StringUtils.isBlank(param.query))
			return null;
		List<Predicate> list = new ArrayList<>();
		for (String string : param.query.split(" ")) {
			if (StringUtils.isBlank(string))
				continue;
			String like = "%" + string + "%";
			list.add(cb.or(cb.like(root.get("no"), like)));
		}
		return (List<Predicate>) list;
	}

	// @PredicateCommand
	// public List<Predicate> merchantIdCommand(CashDetailPageParam param,
	// Root<CashDetail> root, CriteriaQuery<?> query,
	// CriteriaBuilder cb) {
	//
	// if (StringUtils.isBlank(param.merchantId))
	// return null;
	// List<Predicate> list = new ArrayList<>();
	// list.add(cb.equal(root.get("order").get("merchant").get("id"),
	// param.merchantId));
	// return (List<Predicate>) list;
	// }
}
